import Vue from 'vue'

import Cookies from 'js-cookie'



import axios from 'axios'
Vue.prototype.$axios = axios;
axios.defaults.baseURL = '/api'
import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/mixin.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
import permission from './directive/permission'
import './assets/icons' // icon
import './permission' // permission control

import Pagination from "@/components/Pagination";
// 自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar"
import request from "./utils/request.js"
import auto from "./utils/auto.js"
import BaiduMap from 'vue-baidu-map'
// import VueJsonp from 'vue-jsonp'
// Vue.use(VueJsonp)
Vue.use(BaiduMap, {
	/* Visit http://lbsyun.baidu.com/apiconsole/key for details about app key. */
	ak: '8IgNPdwheNO31O8ConU61rHqKgWnODrS'
})
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
// import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
// VXETable.use(VXETablePluginExportXLSX)
Vue.use(VXETable)

// 全局方法挂载

Vue.prototype.request = request
Vue.use(auto)
Vue.prototype.msgSuccess = function(msg) {
	this.$message({
		showClose: true,
		message: msg,
		type: "success"
	});
}

Vue.prototype.msgError = function(msg) {
	this.$message({
		showClose: true,
		message: msg,
		type: "error"
	});
}

Vue.prototype.msgInfo = function(msg) {
	this.$message.info(msg);
}

// 全局组件挂载
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)

Vue.use(permission)

Vue.directive('permission', {
	inserted: (el, binding, vnode) => {
		let flg = false;
		let rol = window.localStorage.getItem("goods__uroles");
		rol = rol.split(",");
		rol.some((currentValue, index, arr) => {
			if (binding.value == currentValue) {
				flg = true;
				return flg;
			}
		})
		if (!flg && binding.value != undefined) { //若没有权限则删除此节点
			el.parentNode.removeChild(el)
		}
	}
})

import {
	filterStrLength,
	formatDate
} from './shop/util/filter.js'
Vue.filter("filterStrLength", function(val, size) {
	return filterStrLength(val, size);
})
Vue.filter("formatDate", function(val) {
	  var data = new Date(val);
	  return formatDate(data, 'yyyy-MM-dd hh:mm:ss');
})

Vue.filter("numFilter", function(value) {
	var value = Math.round(parseFloat(value) * 100) / 100;
	var xsd = value.toString().split(".");
	if (xsd.length == 1) {
		value = value.toString() + ".0";
		return value;
	}
	if (xsd.length > 1) {
		return value;
	}
})
Vue.use(Element, {
	size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false

new Vue({
	el: '#app',
	router,
	store,
	render: h => h(App)
})
